if vim.g.neovide then
    vim.go.linespace = 4

    vim.g.neovide_transparency = 0.9
    vim.g.neovide_cursor_animation_length = 0.06
    vim.g.neovide_scroll_animation_length = 0.2
    vim.g.neovide_cursor_trail_size = 0.4
    vim.g.neovide_position_animation_length = 0.08
    vim.g.neovide_profiler = false

    vim.api.nvim_create_user_command(
        'NeovideSetTransparency',
        function(data)
            local val = tonumber(data.fargs[1])
            if val >= 0 and val <= 100 then
                vim.g.neovide_transparency = val / 100
            end
        end,
        { nargs = 1 }
    )

    local almost_all_mode = { '', '!', 't' }
    vim.keymap.set({ '!', 't' }, '<C-S-v>', '<C-r>+')
    vim.keymap.set(almost_all_mode, '<F9>', function()
        vim.system({ 'neovide' }, { detach = true })
    end)

    local change_scale_factor = function(delta)
        local new = vim.g.neovide_scale_factor + delta
        if new > 0 then
            vim.g.neovide_scale_factor = new
        end
    end
    vim.keymap.set(almost_all_mode, '<C-=>', function()
        change_scale_factor(0.1)
    end)
    vim.keymap.set(almost_all_mode, '<C-->', function()
        change_scale_factor(-0.1)
    end)
end
